package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.FollowService;
import com.example.demo.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/user")
public class FollowController {

    private final FollowService followService;

    @Autowired
    public FollowController(FollowService followService) {
        this.followService = followService;
    }

    //获取粉丝列表，包括粉丝的详细信息（用户名、头像、性别等）
    @GetMapping("/{user_id}/fans")
    public List<User> getFans(@PathVariable Integer user_id) {
        return followService.getFans(user_id); // 返回用户的粉丝列表
    }

    //获取关注列表，包括关注用户的详细信息（用户名、头像、性别等）
    @GetMapping("/{user_id}/followees")
    public List<User> getFollowees(@PathVariable Integer user_id) {
        return followService.getFollowees(user_id); // 返回用户的关注列表
    }

    //关注某个用户
    @PostMapping("/{fan_id}/follow/{followee_id}")
    public String followUser(@PathVariable Integer fan_id, @PathVariable Integer followee_id) {
        boolean result = followService.followUser(fan_id, followee_id); // 调用服务层关注某个用户
        return result ? "Successfully followed!" : "Already following this user."; // 返回消息
    }

    //取消关注某个用户

    @PostMapping("/{fan_id}/unfollow/{followee_id}")
    public String unfollowUser(@PathVariable Integer fan_id, @PathVariable Integer followee_id) {
        boolean result = followService.unfollowUser(fan_id, followee_id); // 调用服务层取消关注某个用户
        return result ? "Successfully unfollowed!" : "Error occurred while unfollowing."; // 返回消息
    }

    @GetMapping("/{user_id}/followers/count")
    public int getFollowerCount(@PathVariable Integer user_id) {
        return followService.getFollowerCount(user_id);
    }

    @GetMapping("/{user_id}/following/count")
    public int getFollowingCount(@PathVariable Integer user_id) {
        return followService.getFollowingCount(user_id);
    }

}
